package ActiveMQ.Cluster;

import org.apache.activemq.ActiveMQConnectionFactory;

import javax.jms.*;

/**
 * Created by brossdong on 2017/12/20.
 */
public class Customer {

    public static void main(String[] args) {
        try {
            //1
            ConnectionFactory connectionFactory = new ActiveMQConnectionFactory(
                    ActiveMQConnectionFactory.DEFAULT_USER,
                    ActiveMQConnectionFactory.DEFAULT_PASSWORD,
                    "failover:(tcp://172.16.113.141:51511,tcp://172.16.113.141:51512,tcp://172.16.113.141:51513)?Randomize=false");
            //2
            Connection connection = connectionFactory.createConnection();
            connection.start();
            //3
            Session session = connection.createSession(Boolean.FALSE, Session.AUTO_ACKNOWLEDGE);
            //4
            Destination destination = session.createQueue("first");
            //5
            MessageConsumer consumer = session.createConsumer(destination);

            while (true) {
                TextMessage msg = (TextMessage) consumer.receive();
                if (msg == null) break;
                System.out.println("收到内容:" + msg.getText());
            }


        }catch (Exception e) {
            e.printStackTrace();
        }
    }


}
